(function ($) { $(document).ready(function () { var windowWidth = $(window).width(); // Responsive language toggle // -------------------------------------------------------------------- $(window).resize(function() { var windowWidth = $(window).width(); if (windowWidth < 1140) { $('.language-container').appendTo('.mega-toggle-blocks-left'); $('.site-header .wp-block-buttons').appendTo('.mega-toggle-blocks-right'); } else { $('.language-container').prependTo('.header-actions'); $('.site-header .wp-block-buttons').appendTo('.site-header--first-row > .wp-block-group'); } }); if (windowWidth < 1140) { $('.language-container').appendTo('.mega-toggle-blocks-left'); $('.site-header .wp-block-buttons').appendTo('.mega-toggle-blocks-right'); } else { $('.language-container').prependTo('.header-actions'); $('.site-header .wp-block-buttons').appendTo('.site-header--first-row > .wp-block-group'); } // Language toggle functionality for TransPerfect // (script embedded under 'Site Settings' in WP dashboard) //-------------------------------------------------------------------- (function() { // Define the Spanish domain constant const spanishDomain = 'https://espanol.ouc.com'; const englishDomain = 'https://www.ouc.com'; // Get the current hostname for the English domain // const englishDomain = window.location.origin; // Determine the current URL and language state const currentUrl = window.location.href; const isSpanish = currentUrl.startsWith(spanishDomain); let currentLanguage = isSpanish ? 'es' : 'en'; sessionStorage.setItem("Locale", currentLanguage); // console.log(sessionStorage.getItem("Locale")); // Add a body class for the current language $('body').addClass(`language-${currentLanguage}`); // Toggle the active class on the language toggle button based on the domain $('#languageToggle').toggleClass('active', isSpanish); // Helper function to update all anchor links by replacing one domain with another function updateLinks(oldDomain, newDomain) { $('a').each(function() { let href = $(this).attr('href'); if (href) { $(this).attr('href', href.replace(oldDomain, newDomain)); } }); } // alert(currentLanguage); // Update links based on the current language if (currentLanguage == 'es') { // For Spanish, delay slightly (if needed) to ensure DOM readiness setTimeout(() => { updateLinks(englishDomain, spanishDomain); }, 250); } else { updateLinks(spanishDomain, window.location.origin); } // Handle language toggle click: switch to the other domain while keeping the current path $('#languageToggle').on('click', function () { const currentPath = window.location.pathname; if (isSpanish) { window.location.href = englishDomain + currentPath; } else { window.location.href = spanishDomain + currentPath; } }); // Change Outage Map link if language is Spanish if (currentLanguage == 'es') { $('.outage-map-link').find('a').attr('href', 'https://outagemap.ouc.com/external/default.html/?language=es-US'); } })(); // Remove inner element from the WP navigation block items // (the tag interferes with the language translation software) // -------------------------------------------------------------------- $('a.wp-block-navigation-item__content').each(function() { // Extract the text content from the var spanText = $(this).find('span.wp-block-navigation-item__label').text(); // Remove the element $(this).find('span.wp-block-navigation-item__label').remove(); // Set the text content directly to the tag $(this).text(spanText); }); // Shorten language toggle labels on mobile // ------------------------------------------------------- if (windowWidth < 768) { $('.language-label-en').html('EN'); $('.language-label-es').html('ES'); } $(window).resize(function() { const windowWidth = $(window).width(); if (windowWidth < 768) { $('.language-label-en').html('EN'); $('.language-label-es').html('ES'); } else { $('.language-label-en').html('English'); $('.language-label-es').html('Spanish'); } }); }); })(jQuery);